<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/model/device.html">
<link rel="import" href="/tracing/model/model.html">
<link rel="import" href="/tracing/model/power_series.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  const Device = tr.model.Device;
  const Model = tr.Model;
  const PowerSeries = tr.model.PowerSeries;

  test('updateBounds', function() {
    const device = new Device(new Model());
    device.powerSeries = new PowerSeries(device);

    // Verify that the bounds match the lowest and highest timestamps.
    device.powerSeries.addPowerSample(100, 5);
    device.powerSeries.addPowerSample(200, 5);
    device.updateBounds();

    assert.strictEqual(device.bounds.min, 100);
    assert.strictEqual(device.bounds.max, 200);

    // Add a new sample and verify that the bounds change.
    device.powerSeries.addPowerSample(700, 5);
    device.updateBounds();

    assert.strictEqual(device.bounds.min, 100);
    assert.strictEqual(device.bounds.max, 700);
  });

  test('shiftTimestampsForward', function() {
    const device = new Device(new Model());
    device.powerSeries = new PowerSeries(device);

    device.powerSeries.addPowerSample(100, 2);
    device.powerSeries.addPowerSample(200, 2);
    device.shiftTimestampsForward(2);

    assert.strictEqual(device.powerSeries.samples[0].start, 102);
    assert.strictEqual(device.powerSeries.samples[1].start, 202);
  });

  test('childEventContainers_noPowerSeries', function() {
    const device = new Device(new Model());
    const childEventContainers = [];
    for (const container of device.childEventContainers()) {
      childEventContainers.push(container);
    }
    assert.deepEqual(childEventContainers, []);
  });

  test('childEventContainers_powerSeries', function() {
    const device = new Device(new Model());
    device.powerSeries = new PowerSeries(device);
    const childEventContainers = [];
    for (const container of device.childEventContainers()) {
      childEventContainers.push(container);
    }
    assert.deepEqual(childEventContainers, [device.powerSeries]);
  });
});
</script>
